﻿using System.ComponentModel;
using System.Windows.Input;
using Client.Wpf.Annotations;
using Client.Wpf.Commands;
using Client.Wpf.HelloServiceReference;

namespace Client.Wpf.ViewModels
{
  public class MainWindowVM : IResult, INotifyPropertyChanged
  {
    private readonly HelloServiceClient _client;
    private string _result;

    public MainWindowVM()
    {
      _client = new HelloServiceClient();

      SendMessage = new SendMessageCommand(_client, this);
    }

    public ICommand SendMessage { get; private set; }

    public event PropertyChangedEventHandler PropertyChanged;

    public string Result
    {
      get { return _result; }
      set
      {
        if (value == _result) return;
        _result = value;
        OnPropertyChanged("Result");
      }
    }

    [NotifyPropertyChangedInvocator]
    protected virtual void OnPropertyChanged(string propertyName)
    {
      PropertyChangedEventHandler handler = PropertyChanged;
      if (handler != null) handler(this, new PropertyChangedEventArgs(propertyName));
    }
  }
}